home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / MenuBar.C < prev    next >
C/C++ Source or Header  |  1992-06-30  |  4KB  |  202 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "MenuBar.h"
  6.  
  7. #include "Class.h"
  8. #include "OrdColl.h"
  9. #include "Clipper.h"
  10. #include "Look.h"
  11. #include "Box.h"
  12. #include "Filler.h"
  13. #include "Window.h"
  14. #include "Buttons.h"
  15. #include "PopupItem.h"
  16. #include "Menu.h"
  17.  
  18. //---- MenuItemSelector --------------------------------------------------------
  19.  
  20. class MenuItemSelector: public Command {
  21.     MenuBar *mb;
  22.     VObject *last;
  23. public:
  24.     MenuItemSelector(MenuBar*);
  25.     void TrackFeedback(Point, Point, bool)
  26.     { }
  27.     Command *TrackMouse(TrackPhase, Point, Point, Point);
  28. };
  29.  
  30. MenuItemSelector::MenuItemSelector(MenuBar *m)
  31.     mb= m;
  32.     last= 0;
  33. }
  34.  
  35. Command *MenuItemSelector::TrackMouse(TrackPhase atp, Point, Point, Point np)
  36. {
  37.     VObject *itemptr= mb->FindItem(np);
  38.     
  39.     switch (atp) {
  40.     case eTrackPress:
  41.     if (itemptr)
  42.         itemptr->DoTrackMouse(eTrackPress, np);
  43.     break;
  44.     case eTrackMove:
  45.     if (itemptr != last) {
  46.         if (last)
  47.         last->DoTrackMouse(eTrackExit, np);
  48.         if (itemptr)
  49.         itemptr->DoTrackMouse(eTrackPress, np);
  50.         last= itemptr;
  51.     } else if (itemptr)
  52.         itemptr->DoTrackMouse(eTrackMove, np);
  53.     break;
  54.     case eTrackRelease:
  55.     if (itemptr)
  56.         itemptr->DoTrackMouse(eTrackRelease, np);
  57.     return gNoChanges;
  58.     case eTrackExit:
  59.     if (itemptr)
  60.         itemptr->DoTrackMouse(eTrackExit, np);
  61.     return gNoChanges;
  62.     case eTrackIdle:
  63.     break;
  64.     }
  65.     return this;
  66. }
  67.  
  68. //---- MenuBar -----------------------------------------------------------------
  69.  
  70. NewMetaImpl0(MenuBar,Box);
  71.  
  72. MenuBar::MenuBar(Collection *c) : Box(cIdNone, Point(2, 0), gPoint4,
  73.                     (VObjAlign)(eVObjVBase+eVObjHGapExpand))
  74. {
  75.     Add(mb= new HBox(gPoint0, (VObjAlign)(eVObjVCenter|eVObjHExpand), (SeqCollection*)c));
  76.  
  77.     help= new Filler(gPoint4, eVObjVFixed);
  78.     help->Disable();
  79. }
  80.  
  81. VObject *MenuBar::FindItem(Point p)
  82. {
  83.     Iter next(mb->MakeIterator());
  84.     register VObject *vop;
  85.     
  86.     while (vop= (VObject*) next())
  87.     if (vop->ContainsPoint(p))
  88.         if (vop->IsKindOf(PullDownButton))
  89.         return vop;
  90.     return 0;
  91. }
  92.  
  93. Menu *MenuBar::FindMenu(int id)
  94. {
  95.     Iter next(mb->MakeIterator());
  96.     register VObject *vop;
  97.     
  98.     while (vop= (VObject*) next())
  99.     if (vop->GetId() == id && vop->IsKindOf(PullDownButton))
  100.         return ((PullDownButton*)vop)->MyMenu();
  101.     return 0;
  102. }
  103.  
  104. int MenuBar::CheckKey(Token &t)
  105. {
  106.     int cmd= cIdNone;
  107.     Iter next(mb->MakeIterator());
  108.     register VObject *vop;
  109.     
  110.     while (vop= (VObject*) next()) {
  111.     if (vop->IsKindOf(PullDownButton)) {
  112.         PullDownButton *pdb= (PullDownButton*) vop;
  113.         cmd= pdb->MyMenu()->CheckKey(t);
  114.         if (cmd != cIdNone) {
  115.         pdb->Flush();
  116.         return cmd;
  117.         }
  118.     }
  119.     }
  120.     return cIdNone;
  121. }
  122.  
  123. Metric MenuBar::GetMinSize()
  124. {
  125.     Metric m(gLook->MenuBarLayout()->GetMinSize(this));
  126.     SetFlag(eVObjHFixed, At(0)->TestFlag(eVObjHFixed));
  127.     SetFlag(eVObjVFixed, At(0)->TestFlag(eVObjVFixed));
  128.     return m;
  129. }
  130.  
  131. void MenuBar::SetExtent(Point e)
  132. {
  133.     VObject::SetExtent(e);
  134.     gLook->MenuBarLayout()->SetExtent(this, e);
  135. }
  136.  
  137. void MenuBar::SetOrigin(Point at)
  138. {
  139.     VObject::SetOrigin(at);
  140.     gLook->MenuBarLayout()->SetOrigin(this, at);
  141. }
  142.  
  143. void MenuBar::Draw(Rectangle r)
  144. {
  145.     At(0)->DrawAll(r);
  146.     gLook->MenuBarLayout()->Adorn(this, r, 0);
  147. }
  148.  
  149. void MenuBar::AddMenu(Menu *pdm)
  150. {
  151.     if (pdm) {
  152.     PullDownButton *pdb= new PullDownButton(pdm->GetId(), pdm);
  153.     /*
  154.     if (help) {
  155.         mb->Remove(help);
  156.         mb->Add(pdb);
  157.         mb->Add(help);
  158.     } else
  159.         mb->Add(pdb);
  160.     */
  161.     /*
  162.     if (mb->Size() <= 0)
  163.         Add(pdb);
  164.     else
  165.         mb->Add(pdb);
  166.     */
  167.     if (mb->Size() <= 0) {
  168.         mb->Add(help);
  169.         mb->Add(pdb);
  170.     } else {
  171.         SeqCollection *s= mb->GetList();
  172.         s->AddBeforePtr(pdb, help);
  173.         pdb->SetContainer(mb);
  174.         if (mb->IsOpen())
  175.         pdb->Open();
  176.     }
  177.     }
  178. }
  179.  
  180. /*
  181. void MenuBar::AddHelpMenu(Menu *pdm)
  182. {
  183.     if (pdm) {
  184.     help= new PullDownButton(pdm->GetId(), pdm);
  185.     mb->Add(help);
  186.     }
  187. }
  188. */
  189.  
  190. Command *MenuBar::DispatchEvents(Point lp, Token &t, Clipper *vf)
  191. {
  192.     if (t.Code == eEvtLeftButton && t.Flags == 0) {
  193.     Command *cmd= new MenuItemSelector(this);
  194.     if (cmd && cmd != gNoChanges && vf)
  195.         cmd= vf->TrackInContent(lp, t, cmd);
  196.     return gNoChanges;
  197.     }
  198.     return CompositeVObject::DispatchEvents(lp, t, vf);
  199. }
  200.  
  201.